var pageNum = null;
var pageSize = 10;
let vm = new Vue({
    el: '.main-content',
    data: {
        pageInfo: {},
        statute:{},
        condition:{
            type:''
        },
        active: true
    },
    methods: {

        getPage: function (pageNum, pageSize) {
            selectPage(pageNum, pageSize)
        },

        selectPage2:function () {
            axios({
                url: `/gugaunjia/statute/findAll/${pageNum}/${pageSize}`,
                params:this.condition
            }).then(response => {
                vm.$data.pageInfo = response.data;
            }).catch(error => {
                layer.msg(error.message)
            })
        },
        selectAll:function () {
            this.condition={
                type:''
            }
           this.selectPage2()
        },

        insert: function () {
            axios({
                url: "/gugaunjia/statute/insert",
                method: "POST",
                data: this.statute
            }).then(response => {
                //清空
                this.statute = {};
                //切换
                this.active = !this.active;

                layer.msg("添加成功")
                selectPage(pageNum, pageSize);
            }).catch(error => {
                alert("请完成填写")
            })
        },
        aa: function () {
            this.active = !this.active
        },

        toUpdate: function (id) {
            layer.open({
                type: 2,
                skin: 'layui-layer-demo', //样式类名
                title: '编辑',
                closeBtn: 0, //不显示关闭按钮
                anim: 2,
                area: ['80%', '80%'],
                shadeClose: true, //开启遮罩关闭
                content: '/gugaunjia/statute/toUpdate',
                success: function (aa, index) {
                    var iframe = window['layui-layer-iframe' + index];
                    iframe.abcd(id)
                },
                end: function () {
                    selectPage(pageNum, pageSize);
                }
            })

        },




        doDelete: function (statute) {
            layer.msg('是否删除', {
                time: 20000, //20s后自动关闭
                btn: ['是', '否'],
                yes: () => {
                    //删除标记（0：正常；1：删除；2：审核；）
                    statute.delFlag = "1";
                    axios({
                        url: "/gugaunjia/statute/updateById",
                        method: "POST",
                        data: statute,
                    }).then(response => {
                        layer.msg("删除成功")
                        this.getPage(pageNum, pageSize)
                    }).catch(error => {
                        layer.msg(error.message)
                    });
                }
            });
        }

    },

    created: function () {
        selectPage(1, 10);
    },
    mounted:function(){
        jeDate({
            dateCell: "#modifydate",
            format:'YYYY-MM-DD',
            zIndex:99999999,
            choosefun:(val)=>{
                console.log(val);
                this.statute.pubDate=val;
            }
        });
    },

});

function selectPage(pageNum, pageSize) {
    this.pageNum = pageNum;
    this.pageSize = pageSize;
    axios({
        url: `/gugaunjia/statute/findAll/${pageNum}/${pageSize}`,
        params:this.condition
    }).then(response => {
        vm.$data.pageInfo = response.data;
    }).catch(error => {
        layer.msg(error.message)
    })
}